home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / gfx / misc / FujiControl.lha / fuji.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-06  |  8.9 KB  |  381 lines

  1. /* Program to communicate with Fuji MX-500 & MX-700 cameras */
  2. #include <stdio.h>
  3. #include <exec/types.h>
  4.  
  5. int debug =  ( 64 | 128);
  6.  
  7. #include "serialport.c"
  8.  
  9. #include "cameracommands.c"
  10.  
  11. #include "primitives.c"
  12.  
  13. #include "debugging.c"
  14.  
  15. /************ main functions ************/
  16.  
  17. void main(int argc, char *argv[])
  18. {
  19.     int i;
  20.  
  21.         if (argc == 1 || (argc==2 && *argv[1]=='?'))
  22.     {
  23.         parseargs(argc,argv);
  24.     }
  25.     else
  26.     {
  27.         setup_comm();
  28.  
  29.         if (attention())
  30.             parseargs(argc,argv);
  31.         else
  32.               printf("!! Camera is not responding.\n");
  33.     }
  34.  
  35.     finish();
  36. }
  37.  
  38.  
  39. finish()
  40. {
  41.     closeserial();
  42.     return(1);
  43. }
  44.  
  45.  
  46. parseargs(int argc, char *argv[])
  47. {
  48.     int i,frame;
  49.     char *filename;
  50.     int understood = 0;
  51.  
  52.     if (argc == 1 || (argc==2 && *argv[1]=='?'))
  53.     {
  54.         printf("Usage:\n %8s ",argv[0]);
  55.          printf("{  DOWNLOAD  { NAME picture-name | FRAME frameno | ALL } [ filename ] }  \n");
  56.         printf("        | {    UPLOAD  filename imagename }                                         \n");
  57.         printf("        | {    DELETE  { NAME name } | { FRAME frameno } | ALL  }                   \n");
  58.         printf("        | {    LIST }                                                               \n");
  59.         printf("        | {    SHOOT [ filename [ DELETE ] ] }                                      \n");
  60.         printf("        | {    SET [ FLASH { OFF | FORCE | REDEYE | AUTO } ]                        \n");
  61.         printf("                   [ RESOLUTION 1280 | 640 | HI | LO ] }                            \n");
  62.         printf("                   [ COMPRESSION BASIC | FINE | NORMAL ]                            \n");
  63.         printf("                   [ ZOOM | NOZOOM ]                                                \n");
  64.         printf("                   [ MACRO | NOMACRO ]                                              \n");
  65.           printf("           }\n");
  66.         printf("\n");
  67.         understood=1;
  68.     }
  69.     else
  70.     {
  71.         uppercase(argv[1]);
  72.  
  73.         if (!strncmp(argv[1],"DOWNLOAD",8))
  74.         {
  75.             understood=1;
  76.             uppercase(argv[2]);
  77.             if (!strncmp(argv[2],"ALL",3)  || argv[2]==NULL)    return(download_all(argv[3]));
  78.             if (!strncmp(argv[2],"NAME",5))
  79.             {
  80.                 printf("!! Downloading by picture name not yet implemented\n");
  81.                 return(0);
  82.             }
  83.             if (!strncmp(argv[2],"FRAME",5))
  84.             {
  85.                 if (!sscanf(argv[3],"%d",&frame)) return(0*printf("!! Bad frame number\n"));
  86.                 return(download_byframe(frame,argv[4]));
  87.             }
  88.             understood=0;
  89.         }
  90.  
  91.         if (!strncmp(argv[1],"UPLOAD",6))
  92.         {
  93.             if (argc==4)
  94.             {
  95.                 understood=1;
  96.                 uppercase(argv[3]);
  97.                 return(send_image(argv[2],argv[3]));
  98.             }
  99.         }
  100.  
  101.         if (!strncmp(argv[1],"DELETE"  ,6))
  102.         {
  103.                understood=1;
  104.             uppercase(argv[2]);
  105.             if (!strncmp(argv[2],"ALL",3)  || argv[2]==NULL)    return(delete_all());
  106.             if (!strncmp(argv[2],"NAME",5))
  107.             {
  108.                 printf("!! Deleting by picture name not yet implemented\n");
  109.                 return(0);
  110.             }
  111.             if (!strncmp(argv[2],"FRAME",5))
  112.             {
  113.                 if (!sscanf(argv[3],"%d",&frame)) return(0*printf("!! Bad frame number\n"));
  114.                 return(delete_byframe(frame));
  115.             }
  116.                understood=0;
  117.         }
  118.  
  119.         if (!strncmp(argv[1],"LIST"    ,4))
  120.         {
  121.             understood=1;
  122.             return(list_all(argv[2]));
  123.         }
  124.  
  125.         if (!strncmp(argv[1],"SHOOT"   ,5))
  126.         {
  127.             understood=1;
  128.             uppercase(argv[3]);
  129.             return(shoot_picture(argv[2],!strncmp(argv[3],"DELETE",6)));
  130.         }
  131.  
  132.         if (!strncmp(argv[1],"SET"     ,3))
  133.         {
  134.             understood=0;
  135.             for( i=2; i<argc; i++ ) uppercase(argv[i]);
  136.             for( i=2; i<argc; i++ )
  137.             {
  138.                 if (!strncmp(argv[i],"FLASH",5)) understood = set_flash(argv[++i]);
  139.                 if (!strncmp(argv[i],"RESOL",5)) understood = set_resolution(argv[++i]);
  140.                 if (!strncmp(argv[i],"COMPR",5)) understood = set_compression(argv[++i]);
  141.                 if (!strncmp(argv[i],"ZOOM" ,4)) understood = set_zoom(1);
  142.                 if (!strncmp(argv[i],"NOZOO",5)) understood = set_zoom(0);
  143.                 if (!strncmp(argv[i],"MACRO",5)) understood = set_macro(1);
  144.                 if (!strncmp(argv[i],"NOMAC",5)) understood = set_macro(0);
  145.             }
  146.             return(1);
  147.         }
  148.  
  149.         if (!strncmp(argv[1],"TEST",4))
  150.         {
  151.             understood=1;
  152.     
  153.             send_image("ram:dsc00224.jpg","dsc00999.jpg");    
  154.  
  155.             understood=0;
  156.         }
  157.  
  158.  
  159.     }
  160.  
  161.  
  162.     if (understood==0) 
  163.     {
  164.         printf("!! I couldn't understand the command line \n");
  165.         return(0);
  166.     }
  167.  
  168.     return(0);
  169. }
  170.  
  171.  
  172.  
  173. uppercase(char *string)
  174. {
  175.     int i;
  176.     if (string==NULL) return(0); 
  177.     for(i=0; i<strlen(string); i++)
  178.     {
  179.         if (string[i]>='a' && string[i]<='z') string[i] -= 32;
  180.     }
  181.     return(strlen(string));
  182. }
  183.  
  184. /****** 'High level' commands ******/
  185.  
  186. download_all(char * filename)
  187. {
  188.     int images,i,chars_received,startnum=1;
  189.     char imagename[80],diskfilename[80];
  190.     
  191.     if (filename)
  192.     {
  193.         printf("@ Download all pictures to files with template %snnnn.jpeg\n",filename);
  194.         images = get_num_pics();
  195.         if (images==0) return(0*printf("!! No images in camera\n"));
  196.         for(i=1; i<=images && attention(); i++)
  197.         {    
  198.             sprintf(diskfilename,"%s%04d.jpeg",filename,startnum++);
  199.             chars_received = get_image(i,diskfilename);
  200.             printf("  Frame %03d to filename %s",i,diskfilename);
  201.             if (chars_received) printf(" successful\n"); else printf(" FAILED\n");
  202.         }
  203.     }
  204.     else
  205.     {
  206.         printf("@ Download all pictures to files with same name as in camera\n",filename);
  207.         images = get_num_pics();
  208.         if (images==0) return(0*printf("!! No images in camera\n"));
  209.         for(i=1; i<=images && attention(); i++)
  210.         {    
  211.             get_image_name(i,imagename);
  212.             sprintf(diskfilename,"%s",imagename,startnum);
  213.             chars_received = get_image(i,diskfilename);
  214.             printf("  Frame %03d to filename %s",i,diskfilename);
  215.             if (chars_received) printf(" successful\n"); else printf(" FAILED\n");
  216.         }
  217.     }    
  218.     return(1);
  219. }
  220.  
  221. download_byframe(int frame,char *filename)
  222. {
  223.     char imagename[80];
  224.     int chars_received;
  225.  
  226.     if (filename)
  227.     {
  228.         printf("@ Download frame %d to file %s\n",frame,filename);
  229.         chars_received = get_image(frame,filename);
  230.         if (chars_received) return(1|printf(" successful\n"));  else return(0*printf(" FAILED\n"));
  231.     }
  232.     else
  233.     {
  234.         printf("@ Download frame %d to file with same name as in camera\n",frame);
  235.         get_image_name(frame,imagename);
  236.         chars_received = get_image(frame,imagename);
  237.         if (chars_received) return(1|printf(" successful\n"));  else return(0*printf(" FAILED\n"));
  238.     }
  239.     return(1);
  240. }
  241.  
  242.  
  243. delete_all()
  244. {
  245.     int images,i;
  246.  
  247.     printf("@ Delete all pictures in camera\n");
  248.     images = get_num_pics();
  249.     if (images==0) return(0*printf("!! No images in camera\n"));
  250.     for(i=images; i>=1 && attention(); i++)
  251.     {    
  252.         printf("  Deleting %04d of %04d - ",i,images);
  253.         if (delete_image(i)) 
  254.             printf(" successful\n\x0b"); 
  255.         else 
  256.             printf(" FAILED\n\x0b");
  257.     }
  258.     printf("\n");
  259.     
  260.     return(1);
  261. }
  262.  
  263. delete_byframe(int frame)
  264. {
  265.     printf("@ Delete frame  %d\n",frame);
  266.     if (delete_image(frame)) 
  267.         printf(" successful\n"); 
  268.     else 
  269.         printf(" failed\n");
  270.  
  271.     return(1);
  272. }
  273.  
  274. list_all(char *filename)
  275. {
  276.     int size,images,i,totsize=0;
  277.     char name[80];
  278.     FILE *fp=NULL;
  279.  
  280.     printf("@ List info about pictures in camera\n");
  281.     images=get_num_pics();    
  282.     
  283.     if (filename) fp=fopen(filename,"w");
  284.  
  285.     for (i=1;i<=images; i++)
  286.     {
  287.         size=get_image_size(i);
  288.         get_image_name(i,name);
  289.         if (fp) fprintf(fp,"%4d  %0.20s %8d\n",i,name,size);
  290.         printf("%4d  %0.20s %8d\n",i,name,size);
  291.         totsize+=size;
  292.     }
  293.     printf("      %0.20s %8d\n","Total:",totsize);
  294.     if (fp) fprintf(fp,"      %0.20s %8d\n","Total:",totsize);
  295.     if (fp) fclose(fp);
  296.     return(1);
  297. }
  298.  
  299. shoot_picture(char *filename,int delete)
  300. {
  301.     int frame=0,status=0;
  302.     
  303.     charge_flash(200);
  304.     shoot(&frame,&status);
  305.  
  306.     if (filename==NULL) 
  307.     {
  308.         printf("@ Shoot a picture and leave it in the camera\n");
  309.     }
  310.     else
  311.     {
  312.         printf("@ Shoot a picture and download it to file %s",filename);
  313.         get_image(frame,filename);
  314.     }
  315.     if (delete)    
  316.     {
  317.         printf(" and then delete it from the camera");
  318.         delete_image(frame);
  319.     }
  320.     printf("\n");
  321.     return(1);
  322. }
  323.  
  324. set_flash(char *flashmode)
  325. {
  326.     int mode=-1;
  327.     if (!strncmp(flashmode,"OFF"   ,3)) mode = 0;
  328.     if (!strncmp(flashmode,"FOR"   ,3)) mode = 1;
  329.     if (!strncmp(flashmode,"RED"   ,3)) mode = 2;
  330.     if (!strncmp(flashmode,"AUT"   ,3)) mode = 3;
  331.  
  332.     if (mode==-1) return(0*printf("!! The flashmode you chose is not supported\n"));
  333.     
  334.     printf("@ Flash mode set to %d - %s\n",mode,flashmode);
  335.     set_flashmode(mode);
  336.     return(1);
  337. }
  338.  
  339. set_resolution(char *resol)
  340. {
  341.     int mode=-1;
  342.     if (!strncmp(resol,"1280"  ,4)) mode = 1;
  343.     if (!strncmp(resol,"HI"    ,2)) mode = 1;
  344.     if (!strncmp(resol,"640"   ,3)) mode = 0;
  345.     if (!strncmp(resol,"LO"    ,2)) mode = 0;
  346.     printf("!! Not supported yet\n");
  347.     if (mode==-1) return(0*printf("!! The resolution you chose is not supported\n"));
  348.     printf("@ Resolution set to %d - %s\n",mode,resol);
  349.     return(1);
  350. }
  351.  
  352. set_compression(char *compressmode)
  353. {
  354.     int mode=-1;
  355.     if (!strncmp(compressmode,"BASI"  ,4)) mode = 0;
  356.     if (!strncmp(compressmode,"FINE"  ,4)) mode = 1;
  357.     if (!strncmp(compressmode,"NORM"  ,4)) mode = 2;
  358.     printf("!! Not supported yet\n");
  359.     if (mode==-1) return(0*printf("!! The compressmodeution you chose is not supported\n"));
  360.  
  361.     printf("@ Compression mode set to %d - %s\n",mode,compressmode);
  362.     return(1);
  363. }
  364.  
  365. set_zoom(int zoom_mode)
  366. {
  367.     printf("!! Not supported yet\n");
  368.     if (zoom_mode) printf("@ Zoom enabled\n");
  369.     if (!zoom_mode) printf("@ Zoom disabled\n");
  370.     return(1);
  371. }
  372.  
  373. set_macro(int macro_mode)
  374. {
  375.     printf("!! Not supported yet\n");
  376.     if (macro_mode) printf("@ Macro enabled\n");
  377.     if (!macro_mode) printf("@ Macro disabled\n");
  378.     return(1);
  379. }
  380.  
  381.